<!--查询用户信息，并分页显示查询结果 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="mybean.data.DataByPage" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.rowset.*" %>
<%@ page import="java.util.*" %>
<jsp:useBean id="loginBean" class="mybean.data.login" scope="session"/>
<jsp:useBean id="dataBean" class="mybean.data.DataByPage" scope="session"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>
	<link rel="stylesheet" type="text/css" href="css/reset.css">
	<link rel="stylesheet" type="text/css" href="css/common.css">
	<link rel="stylesheet" type="text/css" href="css/index-1.css">
	<link rel="stylesheet" type="text/css" href="css/index-2.css">
</head>
<body>
	<%@ include file="Ahead.txt" %>
	<div class="Admin-content">			
		<center>	
		<!-- 分页显示查询结果 -->
		<jsp:setProperty name="dataBean" property="pageSize" param="pageSize"/><!-- 设置页大小和目前的页 -->
		<jsp:setProperty name="dataBean" property="currentPage" param="currentPage"/>
		<%
			request.setCharacterEncoding("utf-8");
			response.setContentType("utf-8");
			CachedRowSet rowset=dataBean.getRowSet();
			double sum1=0,sum=0,t=0;//押金总和
			if(rowset== null){
				out.print("<h2>没有查询到相关信息</h2>");
				return;
			}
			else{
				String button="";
				rowset.last();
				int totalRecord=rowset.getRow();
				if(totalRecord==0){
					out.print("<h2>没有查询到相关信息</h2>");
					return ;
				}
			%>
		<h2>当前显示的是用户信息</h2>
		<table>
			<tr style="background-color: #004b97;color: white">
				<th width=180 height=40>用户身份证号</th>
				<th width=100 height=40>账号</th>
				<th width=100 height=40>姓名</th>
				<th width=120 height=40>联系电话</th>
				<th width=100 height=40>账户余额</th>
				<th width=70 height=40>信用分</th>
				<th width=70 height=40>押金</th>
				<th width=80 height=40>订单</th>
			</tr>			
		<% 	try {//加载驱动
			Class.forName("com.mysql.jdbc.Driver");	
			}
			catch(Exception e) {}
			String url = "jdbc:mysql://127.0.0.1:3306/bike?&useSSL=false&serverTimezone=GMT%2B8&allowMultiQueries=true";
			Connection con = null;
			Statement stm=null;
			String condition="select * from user";//计算所有用户的租金总和
			try {//建立与数据库的连接 
				con = DriverManager.getConnection(url,"root","744615");
				stm=con.createStatement();
				ResultSet rs=stm.executeQuery(condition);
				while(rs.next()) {//还有用户
					String deposit2 =rs.getString("Udeposit");
					sum+=Double.parseDouble(deposit2.substring(0));
				}
			}
			catch (SQLException exp){
				System.out.println(exp);
			}
			String s="<h3>用户押金总和:"+sum+"元</h3>";
			out.print(s);//全部记录数
			out.print("全部记录数"+totalRecord);//全部记录数
			int pageSize = dataBean.getPageSize();//每页显示的记录数
			int totalPages=dataBean.getTotalPages();
			if(totalRecord % pageSize==0)  totalPages=totalRecord/pageSize;//总页数
			else	totalPages=totalRecord/pageSize+1;
			dataBean.setPageSize(pageSize);
			dataBean.setTotalPages(totalPages);
			int r=0;
			if(totalPages>=1){
				if(dataBean.getCurrentPage()<1)	dataBean.setCurrentPage(dataBean.getTotalPages());
				if(dataBean.getCurrentPage()>dataBean.getTotalPages())
					dataBean.setCurrentPage(1);
				int index = (dataBean.getCurrentPage()-1)*pageSize+1;
				rowset.absolute(index);//查询位置移动到currentPage页起始位置
				boolean boo=true;
				for(int i=1;i<=pageSize&&boo;i++){
					String number = rowset.getString("Userid");
					String realname = rowset.getString("Uname");
					String name = rowset.getString("Nickname");
					String tel= rowset.getString("Utel");
					String money = rowset.getString("Umoney");
					String credict = rowset.getString("Ucredit");
					String deposit= rowset.getString("Udeposit");
					if(money==null) money="0";
					if(credict==null) credict="0";
					if(deposit==null) deposit="0";
					sum1 +=Double.parseDouble(deposit.substring(0));//这一页显示的押金总和
					//确定用户是否有借车
					condition="select * from orderform where username ='"+name+"'";
					try {//建立与数据库的连接 
						stm=con.createStatement();
						ResultSet rs=stm.executeQuery(condition);
						//System.out.println("r.next()="+r.next());
						if(rs.next()==true) {//该用户已借单车，可以查看
							 button="<form action='lookMyOrder.jsp' method='post'>"+
							 		"<input type='hidden'  name='Nickname' value="+name+" >"+
									"&nbsp;&nbsp;<input type='submit'  value='查看' class='submit'></form>";//隐含传参name 
						}
						else 
							button="没有订单";						
					}
					catch (SQLException exp){
						System.out.println(exp);
					}
			%>
			<tr style="background-color: #c0c0c0;">
				<td height=50><center><%=number %></center></td>
				<td height=50><center><%=name %><center></td>
				<td height=50><center><%=realname %><center></td>
				<td height=50><center><%=tel%></center></td>
				<td height=50><center><%=money %></center></td>
				<td height=50><center><%=credict %></center></td>
				<td height=50><center><%=deposit %><center></td>
				<td height=50><center><%=button %></center></td> 
			</tr>
				<%	
					boo=rowset.next();				
					}
				}
				con.close();//关闭连接
			}				
			%>	
		</table>
		<%@ include file="bypage.txt" %>
   	</center>
    </div>	
	<!--页面底部-->
	<!--所以的页面底部都一样，用一个文本文件存储，所有JSP文件使用嵌入-->
	<%@ include file="footer.txt" %>
</body>
</html>